<template>
  <div class="weather-legend-container" v-if="!['cloud', 'warning'].includes(weatherType)">
    <div style="float:right">
      <div style="display:flex">
        <span style="color:#fff;margin-right: 10px;" v-if="weatherType === 'rain'">降雨</span>
        <div class="weather-legend-group" v-if="colorList && colorList.length > 0">
          <span class="weather-legend-cell" v-for="(item, index) in colorList.slice(0, -1)"
            :style="linearColor(item.color, colorList[index + 1].color)" :key="item.val"><span>{{ item.val }}</span><span
              v-if="item.text" class="text">{{ item.text }}</span></span>
        </div>
      </div>
      <br v-if="weatherType === 'rain'">
      <div style="display:flex" v-if="weatherType === 'rain'">
        <span style="color:#fff;margin-right: 10px;">降雪</span>
        <div class="weather-legend-group" v-if="weatherType === 'rain'">
          <span class="weather-legend-cell" v-for="(item) in colorLines['snow']"
            :style="{ 'backgroundColor': item.color }" :key="item.val"><span>{{ item.val }}</span><span v-if="item.text"
              class="text">{{ item.text }}</span></span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import colorLines from "./mapConfig/config/colorLines";
export default {
  props: {
    weatherType: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      colorLines: colorLines
    };
  },
  computed: {
    colorList() {
      if (!this.weatherType) return [];
      return colorLines[this.weatherType];
    },
    linearColor() {
      return (start, end) => {
        return { "background-image": `linear-gradient(to right,${start},${end})` };
      };
    }
  }
};
</script>

<style lang="less" scoped>
.weather-legend-container {
  width: 100%;
  overflow: hidden;
  right: 10px;
  padding: 6px;
  background: #666;
}

.weather-legend-group {
  width: 340px;
  border-radius: 10px;
  overflow: hidden;
  display: flex;

  .weather-legend-cell {
    flex: 1;
    text-align: center;
    color: #fff;
    font-size: 12px;
    height: 23px;
    line-height: 23px;

    .text {
      display: inline-block;
      width: 50%;
      float: right;
    }
  }
}
</style>
